package algorithmicFoundation.homework.day1;

import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdRandom;

/**
 * 随机字
 * Write a program that reads a sequence of words
 * from standard input and prints one of those words uniformly at random
 * @author 86155
 * @date 2025/07/28
 */
public class RandomWord {
    public static void main(String[] args) {
        int count = 1;
        String champion = "";
        while (!StdIn.isEmpty()) {
            String word = StdIn.readString();
            if (StdRandom.bernoulli(1.0 / count++)) {
                champion = word;
            }
        }
        System.out.println(champion);
    }
}
